package dd.prog2.exercises.set04;

public class Vector2 implements Vector{
	private double v1;
	private double v2;
	private int vLength = 2;

	protected Vector2(){
	}

	@Override
	public String toString() {
		return "V = [ " +this.v1+" "+this.v2+" ]\n";
	}

	@Override
	public Vector add(Vector v2) throws ArithmeticException  {
		if(v2.getLength() != this.getLength())
			throw new ArithmeticException();
		Vector res = new Vector2();
		res.setVi(this.getVi(0) + v2.getVi(0), 0);
		res.setVi(this.getVi(1) + v2.getVi(1), 1);
		res.toString();
		return res;
	}

	@Override
	public Vector sub(Vector v2) throws ArithmeticException  {
		if(v2.getLength() != this.getLength())
			throw new ArithmeticException();
		Vector res = new Vector2();
		res.setVi(this.getVi(0) - v2.getVi(0), 0);
		res.setVi(this.getVi(1) - v2.getVi(1), 1);
		return res;
	}

	@Override
	public double mul(Vector v2) throws ArithmeticException  {
		if(v2.getLength() != this.getLength())
			throw new ArithmeticException();
		return this.getVi(0) * v2.getVi(0) + this.getVi(1) * v2.getVi(1);
	}

//- - - - - - - - - setter - - - - - - - - -
	@Override
	public void setVi(double value, int index) {
		if(index == 0){
			v1 = value;
		} else
			v2 = value;
	}

	@Override
	public void setall(double value) {
		v1 = value;
		v2 = value;
	}

//- - - - - - - - - getter - - - - - - - - -
	@Override
	public double getVi(int index) {
		if(index == 0){
			return v1;
		} else
			return v2;
	}

	@Override
	public int getLength() {
		return this.vLength;
	}


}
